//
//  MoreGoodsShowViewController.m
//  quxiangtao
//
//  Created by xbmios on 2018/8/1.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MoreGoodsShowViewController.h"
#import "ShoppingHotContentTableViewCell.h"

#import "ShoppingGoodsContentViewController.h"
#import "StockGoodsContentViewController.h"


static NSString *moreGoodsCellID = @"moreGoodsCellID";


@interface MoreGoodsShowViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *goodsTableView;

@property (strong, nonatomic) NSMutableArray *arrayM;

@end

@implementation MoreGoodsShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = Colorf2f2f2;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.view addSubview:self.goodsTableView];
    __weak typeof(self) weakSelf = self;
    [self.goodsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.view.mas_top);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
    }];
    
    self.arrayM = [NSMutableArray array];
    NSArray *array = @[
                    
                    @{@"type" : @"1"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"1"},
                    @{@"type" : @"2"},
                    @{@"type" : @"1"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    @{@"type" : @"2"},
                    
                    ];
    [self.arrayM addObjectsFromArray:array];
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return jisuan(225);
    
}


#pragma mark -delegate、datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.arrayM.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    ShoppingHotContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moreGoodsCellID];
    
//    if (!cell) {
//
//
//    }
    
//    ShoppingHotContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moreGoodsCellID];
    
//    if (!cell) {
//
//        cell = [[ShoppingHotContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moreGoodsCellID];
//
//    }
    
    ShoppingHotContentTableViewCell *cell = [[ShoppingHotContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moreGoodsCellID];
    
//    cell.dict = self.arrayM[indexPath.row];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"热销商品点击事件");
    
    if (self.controllerType == 0) {
        
        if (self.supportType == 0) {
            
            NSLog(@"购物===自营====热销商品点击事件");
            ShoppingGoodsContentViewController *vc = [[ShoppingGoodsContentViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
            
        }else {
            
            NSLog(@"购物===非自营====热销商品点击事件");

        }
        
    }else {

        StockGoodsContentViewController *vc = [[StockGoodsContentViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
  
}

#pragma mark -lazy
- (UITableView *)goodsTableView {
    
    if (!_goodsTableView) {
        
        _goodsTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        
        _goodsTableView.backgroundColor = WhiteColor;
        
        _goodsTableView.delegate = self;
        _goodsTableView.dataSource = self;
        
        _goodsTableView.showsVerticalScrollIndicator = NO;
        _goodsTableView.showsHorizontalScrollIndicator = NO;
        
        _goodsTableView.estimatedRowHeight = 0;
        _goodsTableView.estimatedSectionFooterHeight = 0;
        _goodsTableView.estimatedSectionHeaderHeight = 0;
        
        _goodsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        [_goodsTableView registerClass:[ShoppingHotContentTableViewCell class] forCellReuseIdentifier:moreGoodsCellID];
        
        if (@available(iOS 11.0, *)) {
            
            _goodsTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        
        }
        
    }
    
    return _goodsTableView;
    
}

#pragma mark -设置
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
}

@end
